<template>
	<view class="share">
		<view class="select">
			<image class="example" mode="widthFix" :src="oss(url)"></image>
		</view>
		  <u-scroll-list>
		        <view v-for="(item, index) in info.sharegImage" :key="index" class="lists">
		            <image :src="oss(item.url)" class="list" mode="widthFix" @click="url = item.url"></image>
		        </view>
		    </u-scroll-list>
			<view class="btns">
				<view class="btn" @click="down">保存海报</view>
				<view class="btn" @click="show = true">立即邀请</view>
			</view>
			<u-popup :show="show" @close="show = false">
				<view class="waybox">
					<!-- #ifdef APP -->
					<view class="way" @click="WXSceneSession">
						<!-- <image src="../../../static/way/1.png" class="icon" mode="" style="width: 51rpx;height: 43rpx;">
						</image> -->
						<text class="word">微信好友</text>
					</view>
					<view class="way" @click="WXSceneTimeline">
						<!-- <image src="../../../static/way/2.png" class="icon" mode="" style="width: 47rpx;height: 47rpx;">
						</image> -->
						<text class="word">微信朋友圈</text>
					</view>
					<view class="way" @click="shareqq">
						<!-- <image src="../../../static/way/3.png" class="icon" mode="" style="width: 41rpx;height: 44rpx;">
						</image> -->
						<text class="word">QQ</text>
					</view>
					<!-- #endif -->
					<!-- #ifdef MP-WEIXIN -->
					<button class="way" open-type="share">
						<!-- <image src="../../../static/way/1.png" class="icon" mode="" style="width: 51rpx;height: 43rpx;">
						</image> -->
						<text class="word">微信好友</text>
					</button>
					<button class="way" open-type="share">
						<!-- <image src="../../../static/way/2.png" class="icon" mode="" style="width: 51rpx;height: 43rpx;">
						</image> -->
						<text class="word">微信朋友圈</text>
					</button>
					<!-- #endif -->
					
					<view class="way" @click="copy(info.shareUrl)">
						<!-- <image src="../../../static/way/4.png" class="icon" mode="" style="width: 43rpx;height: 43rpx;">
						</image> -->
						<text class="word">推广网址</text>
					</view>
					
				</view>
			</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: '',
				url: '',
				show: false
			};
		},
		onLoad() {
			this.getInfo()
		},
		methods:{
			shareqq() {
				uni.share({
					provider: "qq",
					type: 2,
					imageUrl: this.url,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			WXSceneTimeline() {
				uni.share({
					provider: "weixin",
					scene: "WXSceneTimeline",
					type: 2,
					imageUrl: this.url,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			WXSceneSession() {
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 2,
					imageUrl: this.url,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
			},
			down() {
				uni.downloadFile({
				    url: this.oss(this.url), //仅为示例，并非真实的资源
				    success: (res) => {
				        if (res.statusCode === 200) {
				              uni.saveImageToPhotosAlbum({
				                        filePath: res.tempFilePath,
				                        success: function () {
											uni.$u.toast(`保存成功`)
				                            console.log('save success');
				                        }
				                    });
				        }
				    }
				});
			},
			getInfo(){
				uni.$u.http.post('/share').then(res => {
					if (res.code == 1) {
						this.info = res.data
						this.url = res.data.sharegImage[0].url
					}
				}).catch((res) => {
						
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.share{
		padding-top: 30rpx;
		.waybox {
			display: flex;
			flex-wrap: wrap;
			padding: 40rpx;
		
			.way {
				width: 25%;
				display: flex;
				align-items: center;
				flex-direction: column;
				margin-bottom: 40rpx;
				background: #fff;
				padding: 0;
				margin: 0;
				line-height: 2.55;
				.icon {}
			
				.word {
					color: #191615;
					font-size: 24rpx;
				}
			}
			.way:after{
				display: none;
			}
		}
		.select{
			width: 500rpx;
			margin: 0 auto 20rpx;
		}
		.example{
		width: 500rpx;
		}
		.lists{
			padding: 20rpx;
			.list{
				width: 200rpx;
				margin-left: 20rpx;
			}
		}
		.btns{
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-top: 40rpx;
			.btn{
				width: 260rpx;
				height: 88rpx;
				border-radius: 44rpx;
				background: linear-gradient(to right, #FFDF41, #FFC141);
				color: #191615;
				font-size: 32rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>
